<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head>
    <title>骡窝窝系统管理平台</title>
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/common.js"></script>
    <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/ckeditor/ckeditor.js"></script>
</head>

<body>
<div class="container">
<#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
        <#assign menu = "strategyDetail" />
        <#include "../common/menu.ftl" />
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">平台用户管理</h1>
                </div>
            </div>
            <div class="row">
                <!-- 提交分页的表单 -->
                <form id="searchForm" class="form-inline" method="post" action="/strategyDetail/list.do">
                    <input type="hidden" name="currentPage" id="currentPage" value="1"/>
                    <div class="form-group">
                    </div>
                    <div class="form-group">
                        <label>关键字</label>
                        <input class="form-control" type="text"
                               name="keyword" value="${(qo.keyword)!}" placeholder="请输入关键字"/>
                        </input>
                    </div>

                    <div class="form-group">
                        <button id="query" type="button" class="btn btn-success"><i class="icon-search"></i> 查询</button>
                    </div>
                    <a role="button" class="btn btn-success inputBtn">
                        <span class="glyphicon glyphicon-plus"></span> 添加攻略文章
                    </a>
                </form>
                <script type="text/javascript">
                    $("#query").click(function () {
                        $("#searchForm").submit();
                    })
                </script>
            </div>
            <div class="row">
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>标题</th>
                        <th width="200px">封面</th>
                        <th>发布时间</th>
                        <th>排序</th>
                        <th>攻略类型</th>
                        <th>状态</th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
					<#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.title}</td>
                        <td><img src="${(entity.coverUrl)!}" width="100px"/></td>
                        <td>${(entity.releaseTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                        <td>${entity.sequence}</td>
                        <td>${entity.catalog.name}</td>
                        <td>${entity.stateName}</td>

                        <td>
                            <a role="button" class="btn btn-success inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-leaf"></span> 修改
                            </a>
                        </td>
                    </tr>
                    </#list>
                    </tbody>
                </table>
               <#include "../common/page.ftl"/>
            </div>
            <div id="strategyModal" class="modal" tabindex="-1" role="dialog">
                <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                    aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">编辑/增加</h4>
                        </div>
                        <div class="modal-body">
                            <form id="strategyForm" class="form-horizontal" method="post"
                                  action="/strategyDetail/saveOrUpdate.do" enctype="multipart/form-data"
                                  style="margin: -3px 118px">
                                <input type="hidden" name="id"/>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">标题</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="title" placeholder="标题">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">封面</label>
                                    <div class="col-sm-6">
                                        <img width="200px" id="coverImg"/><!--用来显示-->
                                        <input type="hidden" name="coverUrl"><!--用来提交-->
                                        <input type="file" class="form-control" name="file"><!--用来上传图片-->
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">所属攻略</label>
                                    <div class="col-sm-6">
                                        <select class="form-control" autocomplete="off" name="strategy.id"
                                                id="strategyId">
                                          <#list strategies as s>
                                              <option value="${s.id}">${s.title}</option>
                                          </#list>s
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">攻略类别</label>
                                    <div class="col-sm-6">
                                        <select class="form-control" autocomplete="off" id="catalogId"
                                                name="catalog.id">
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">是否发布</label>
                                    <div class="col-sm-6">
                                        <select class="form-control" autocomplete="off" name="state">
                                            <option value="false">否</option>
                                            <option value="true">是</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">排序</label>
                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="sequence" placeholder="排序">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <textarea rows="10" cols="80" name="strategyContent.content" id="editor">

                                    </textarea>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <a href="javascript:void(0);" class="btn btn-primary" id="saveBtn" aria-hidden="true">保存</a>
                            <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <style>
        #contentModal img {
            width: 100%;
        }

        #contentModal .modal-body {
            max-height: 600px;
            overflow-y: scroll;
        }
    </style>
    <script type="text/javascript">
        //初始化编辑器
        var editor = CKEDITOR.replace('editor');
        $("#strategyId").change(function () {
            var strategyId = $(this).val();
            $.get("/strategyCatalog/listByStrategyId.do", {strategyId: strategyId}, function (data) {
                temp = "";
                $.each(data, function (index, ele) {
                    temp += " <option value='" + ele.id + "'>" + ele.name + "</option>"
                });
                $("#catalogId").html(temp);
            })
        });

        $(".inputBtn").click(function () {
            $("#strategyForm input").val("");
            $("#strategyForm select").val("");
            editor.setData("");
            var json = $(this).data("json");
            //回显数据
            if (json) {
                $("#strategyForm input[name='id']").val(json.id);
                $("#strategyForm input[name='title']").val(json.title);
                $("#coverImg").attr("src", json.coverUrl);
                //回显到隐藏域,用于提交表单,因为img不是表单的属性,不能用来提交
                $("#strategyForm input[name='coverUrl']").val(json.coverUrl);

                $("#strategyForm select[name='state']").val(json.state + "");
                $("#strategyForm input[name='sequence']").val(json.sequence);
                //回显所属攻略下拉框
                $("#strategyForm select[name='strategy.id']").val(json.strategyId);
                //查询该攻略对应的分类集合
                $.get("/strategyCatalog/listByStrategyId.do", {strategyId: json.strategyId}, function (data) {
                    temp = "";
                    $.each(data, function (index, ele) {
                        temp += " <option value='" + ele.id + "'>" + ele.name + "</option>"
                    });
                    $("#catalogId").html(temp);
                    //回显攻略分类
                    $("#strategyForm select[name='catalog.id']").val(json.catalogId);
                });

                //获取文章内容
                $.get("/strategyDetail/getContentById.do",{detailId:json.id},function (data) {
                    console.log(data);
                    editor.setData(data.content);
                })



            }
            $("#strategyModal").modal("show")
        });
        $("#saveBtn").click(function () {
            //把ckeditor的内容设置到textarea中
            var data = editor.getData();
            $("#strategyForm textarea[name='strategyContent.content']").html(data);
            $("#strategyForm").ajaxSubmit(function (data) {
                doSuccess();
            })
        })
    </script>
</body>
</html>
